using System;
using System.Collections.Generic;
using System.Text;
using GraphConstructor;
using System.ComponentModel;
using PhoneNetwork.AntColony;
//using Simulation;

namespace PhoneNetwork
{
    [Serializable, TypeConverter(typeof(ExpandableObjectConverter))]
    public class Phone
    {
        //private static LCGRandom PhoneID = new LCGRandom(9, 7, 64, 10);
        private Node _parent;
        public Node Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }
        private bool _isBusy = false;
        public bool IsBusy
        {
            get { return _isBusy; }
            set { _isBusy = value; }
        }
        private bool _visited = false;
        public bool Visited
        {
            get { return _visited; }
            set { _visited = value; }
        }
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private Dictionary<Node, PheromoneTable> _pheromoneTables;
        public Dictionary<Node, PheromoneTable> PheromoneTables
        {
            get { return _pheromoneTables; }
            set { _pheromoneTables = value; }
        }
        private List<PhoneCall> _calls;
        public List<PhoneCall> Calls
        {
            get { return _calls; }
            set { _calls = value; }
        }

        //private TimeAdvance _nextCall;
        //public TimeAdvance NextCall
        //{
        //    get { return _nextCall; }
        //    set { _nextCall = value; }
        //}

        public Phone(string name, Node Parent)
        {
            _name = name;
            _parent = Parent;
            _pheromoneTables = new Dictionary<Node, PheromoneTable>();
            _calls = new List<PhoneCall>();
        }
        public override bool Equals(object obj)
        {
            if (obj is Phone)
                return Name.Equals((obj as Phone).Name);
            else
                return false;
        }

        public static bool Connect(Node node, PhoneCall c, Node node_3)
        {
            Phone phone = node.Data as Phone;
            if (node.Value != 0)
            {
                phone.Calls.Add(c);
                return true;
            }
            return false;
        }
        public void GenerateDefaultPheromoneTables(IGraph g)
        {
            // create a table for each of the other nodes on the network
            if (_pheromoneTables == null)
                _pheromoneTables = new Dictionary<Node, PheromoneTable>();
            _pheromoneTables.Clear();
            foreach (Node n in g.Nodes)
                //if (this != n.Data) // TODO: this must be uncommented. find a way such that the Generator doesn't generate duplicate nodes.
                    _pheromoneTables.Add(n, new PheromoneTable(n, this.Parent.Adj));
        }
    }
}
